package bloodfang.server;

import java.net.*;
import java.io.*;
 
public class BloodfangServerThread extends Thread {
    private Socket socket = null;
 
    public BloodfangServerThread(Socket socket) {
    	super("BloodfangServerThread");
    	this.socket = socket;
    }
 
    public void run() {
 
	    try {
	        PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
	        BufferedReader in = new BufferedReader(
	                    new InputStreamReader(
	                    socket.getInputStream()));
	 
	        String inputLine, outputLine;
	        BloodfangProtocol kkp = new BloodfangProtocol();
	        
	        
	        while ((inputLine = in.readLine()) != null) {
	        	outputLine = kkp.processInput(inputLine);
		        out.println(outputLine);
		        if (outputLine.equalsIgnoreCase("Bye"))
		            break;
	        }
	        out.close();
	        in.close();
	        socket.close();
	 
	    } catch (IOException e) {
	        e.printStackTrace();
	    }
    }
}
